import request from "@/util/request";
import user from "@/store/user";

export function login(user){
    return request({
        url: '/authentication/login',
        method: 'post',
        data: user
    })
}

export function addUser(data){
    return request({
        url: '/user/add_from_admin',
        method: 'post',
        data: data
    })
}

export function logout(){
    return request({
        url: '/authentication/logout',
        method: 'post'
    })
}

export function register(userInfo){
    return request({
        url: '/authentication/register',
        method: 'post',
        data: userInfo
    })
}


export function deleteUserById(id){
    return request({
        url: '/user/delete/' + id,
        method: 'delete'
    })
}

export function checkUsername(username){
    return request({
        url: '/user/checkUsername?userName='+username,
        method: 'get'
    })
}

export function list(){
    return request({
        url: '/user/list',
        method: 'get'
    })
}


export function pageUser(pageNum, pageSize, userName){
    return request({
        url: '/user/page?pageNum=' + pageNum + '&pageSize=' + pageSize + '&userName=' + userName,
        method: 'get'
    })
}

export function getRoleByUserId(userId){
    return request({
        url: '/user/getRoleByUserId?userId=' + userId,
        method: 'get'
    })
}


export function getUserInfo(id){
    return request({
        url: '/user/userInfoById?id='+id,
        method: 'get'
    })
}

export function updatePassword(password){
    return request({
        url: '/user/update_password',
        method: 'post',
        data: password
    })
}

export function updateUserInfo(user){
    return request({
        url: '/user/update',
        method: 'post',
        data: user
    })
}

export function updateUserAndUserRole(userRole){
    return request({
        url: '/user/updateUserAndUserRole',
        method: 'post',
        data: userRole
    })
}